<?php

class Core_Action_Admin_System_Mail_Transport_Ases extends Action_Admin
{
	public function execute($request, $initial = false, $script = null)
	{
		if ($initial)
		{
			Agilet::setVar('breadcrum', array(
				array(
					'url' => 'admin/system',
					'label' => 'system'
				),
				array(
					'url' => 'admin/system/mail',
					'label' => 'mail'
				),
				array(
					'url' => 'admin/system/mail/transport',
					'label' => 'mail transport'
				),
				array(
					'url' => 'admin/system/mail/ases',
					'label' => 'Amazon SES'
				),
			));

		}

		$form = Form::factory('core/admin/mail/transport/ases');

		$name = 'mail/transport';

		if ($request -> isPost() && $form -> isValid($_POST))
		{
			$data = $form -> getData();

			unset($data['buttons']);

			/**
			 * update confure data.
			 */
			Config::instance() -> write($name, $data);

			/**
			 * ckear mail transport settings
			 */
			Cache::instance() -> remove($name);

			$form -> setNotice('Saved!');
		}

		$request -> response = View::render($script = 'core/html/admin/edit', $data = array(
			'form' => $form,
			'title' => 'Amazon SES'
		));
	}

}
